var app = getApp()
var QQMapWX = require('../../utils/qqmap-wx-jssdk.js');
Page({
  data: {
    objarr: [],
    position:[],
    width:0,
    imgheight:0,
    indexdata:{},
    height:0,
    currentTab:1,
    page: 1,
    pagesize: 5,
    totalpage: 0,//最大页数
    nomore: true,
    isfenlei:false,
    fenleiarr:[],
    is_mine:0,
    absent:0
  },
  onShareAppMessage: function (res) {
    let member_id = app.globalData.userInfo.member_id
    return {
      title: '成纪先锋微平台',
      path: '/pages/three-one/meeting_topic?inviter_id=' + member_id,
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },
  onLoad: function (options) {
    var that = this;
    console.log(wx.getStorageSync('rd_session'))
    
    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        that.setData({
           width: res.windowWidth,
           height:res.windowHeight })
      }
    })
    this.getmeeting()
  },
  getmeeting(){
    let par = {
      rd_session: wx.getStorageSync('rd_session'),
      page: this.data.page,
      page_size: this.data.pagesize
    }
    app.ajax("meeting_topic", par, (data, err) => {
      let arr = []
      for (let item of data.data.list) {
        arr.push(item);
      }
      this.setData({
        objarr:arr,
        totalpage: data.data.total_page
      })
    })
  },
  getmeetingmember(){
    let par = {
      types: this.data.currentTab2,
      is_mine:this.data.is_mine,
      absent:this.data.absent,
      rd_session: wx.getStorageSync('rd_session'),
      page: this.data.page,
      page_size: this.data.pagesize
    }
    app.ajax("member_meeting_topic", par, (data, err) => {
      if(data.result == 'success'){
        let arr = []
        for (let item of data.data.list) {
          arr.push(item);
        }
        this.setData({
          objarr: arr, 
          totalpage: data.data.total_page
        })
      }else{
        wx.showModal({
          title: '提示',
          content: '您需要进行实名认证',
          success: function (res) {
            if (res.confirm) {
              wx.navigateTo({
                url: '/pages/mine/login',
              })
            } else if (res.cancel) {
            }
          }
        })
      }
      
    })
  },
  clicktab(e) {
    let tab = e.currentTarget.dataset.tab
    if (this.data.currentTab != tab) {
      this.setData({
        currentTab: tab,
        page: 1,
      })
      if(tab == '1'){
        this.getmeeting()
      }else{
        if(tab == '2'){
          this.setData({
            is_mine:0,
            absent:0
          })
        }else if(tab == '3'){
          this.setData({
            is_mine: 1,
            absent: 0
          })
        } else if (tab == '4') {
          this.setData({
            is_mine: 1,
            absent: 1
          })
        }
        this.getmeetingmember()
      }
    }
  },
  
  //滑动到底部 上拉加载
  scrollBottom: function () {
    this.data.page++
    if (this.data.page > this.data.totalpage) {
      this.setData({
        nomore: false
      })
    } else {
      
      if (this.data.currentTab == '1') {
        this.getmeeting2()
      } else {
        if (this.data.currentTab == '2') {
          this.setData({
            is_mine: 0,
            absent: 0
          })
        } else if (this.data.currentTab == '3') {
          this.setData({
            is_mine: 1,
            absent: 0
          })
        } else if (this.data.currentTab == '4') {
          this.setData({
            is_mine: 1,
            absent: 1
          })
        }
        this.getmeetingmember2()
      }
    }

  },

  getmeeting2() {
    let par = {
      types: this.data.currentTab2,
      rd_session: wx.getStorageSync('rd_session'),
      page: this.data.page,
      page_size: this.data.pagesize
    }
    app.ajax("meeting_topic", par, (data, err) => {
      let arr = this.data.objarr;
      for (let item of data.data.list) {
        arr.push(item);
      }
      this.setData({
        objarr: arr
      })
    })
  },
  getmeetingmember2() {
    let par = {
      types: this.data.currentTab2,
      is_mine: this.data.is_mine,
      absent: this.data.absent,
      rd_session: wx.getStorageSync('rd_session'),
      page: this.data.page,
      page_size: this.data.pagesize
    }
    app.ajax("member_meeting_topic", par, (data, err) => {
      if (data.result == 'success') {
        let arr = this.data.objarr;
        for (let item of data.data.list) {
          arr.push(item);
        }
        this.setData({
          objarr: arr
        })
      } else {
        wx.showModal({
          title: '提示',
          content: data.message,
        })
      }

    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  
  imageLoad(e) {
    let that = this
    this.setData({
      imgheight: app.fixImgW(e, that.data.width),
    })
  },

 
  
});